package com.dzl.util;

import java.io.IOException;
import java.math.BigDecimal;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
 * 
 * @Description:针对Bigdecimal类型保留两位小数
 * @author liufan
 * @time:2021年4月24日 下午4:01:48
 */
public class CustomBigdecimalSerialize extends JsonSerializer<BigDecimal>{
	
	public CustomBigdecimalSerialize() {
		
	}
	@Override
	public void serialize(BigDecimal value, JsonGenerator gen, SerializerProvider serializers)
			throws IOException, JsonProcessingException {
		gen.writeString(value.setScale(2, BigDecimal.ROUND_HALF_DOWN).toString());
	}
	
}
